import { mongo } from "../mogoConfig"
/**
 * distinct
 * 查询文档中，某字段的所有非重复值
 * 
 */

const run = async () => {
    const db = mongo.db("sample_mflix")
    const moiveTB = db.collection("movies")

    const result1 = await db.command({
        distinct: "movies",
        key: "year",
        query: { year: { $gte: 1914 } }
    })
    console.log("结果1-----------------------------")
    console.log(JSON.stringify(result1))

    const result2 = await moiveTB.distinct("year", { year: { $gte: 1914 } })
    console.log("结果2-----------------------------")
    console.log(JSON.stringify(result2))

}



run()
    .catch((error) => {
        console.log(error)
    })
    .finally(() => {
        mongo.close()
        console.log("执行结束")
    })